﻿using Kingdee.BOS;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FormPlugin.Ronma
{
    [Description("润马：应付单通过API创建时，触发含税单价值更新事件"), HotUpdate]
    public class ApBeforSave : AbstractBillPlugIn
    {
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            base.BeforeSave(e);
            if (this.Context.ServiceType != WebType.WebService)
            {
                return;
            }
            var obj = this.Model.DataObject;
            DynamicObjectCollection rows = obj["AP_PAYABLEENTRY"] as DynamicObjectCollection;
            for (int i = 0; i < rows.Count; i++)
            {
                this.View.InvokeFieldUpdateService("FPriceQty", i);
                this.View.InvokeFieldUpdateService("FTaxPrice", i);
                this.View.InvokeFieldUpdateService("FEntryTaxRate", i);
            }
            var json = JsonConvert.SerializeObject(rows);
        }
    }
}
